package cs2340.todolist.JUnit;



import java.util.ArrayList;
import java.util.Date;

import org.junit.Test;

import cs2340.todolist.model.ToDoItem;
import cs2340.todolist.model.utility.SearchEngine;
import cs2340.todolist.model.utility.SearchEngine.FilterDate;
import cs2340.todolist.model.utility.SearchEngine.FilterType;



public class TestDateFilter {
    private ToDoItem compareMins1 = quickItem(new Date(2012,1,1,1,15));
    private ToDoItem compareMins2 = quickItem(new Date(2012,1,1,1,30));
    private ToDoItem compareMins3 = quickItem(new Date(2012,1,1,1,45));

    private ToDoItem compareHours1 = quickItem(new Date(2012,1,1,1,45));
    private ToDoItem compareHours2 = quickItem(new Date(2012,1,1,2,45));
    private ToDoItem compareHours3 = quickItem(new Date(2012,1,1,3,45));
    
    private ToDoItem compareDay1 = quickItem(new Date(2012,1,1,1,45));
    private ToDoItem compareDay2 = quickItem(new Date(2012,1,2,1,45));
    private ToDoItem compareDay3 = quickItem(new Date(2012,1,3,1,45));

    private ToDoItem compareMonth1 = quickItem(new Date(2012,1,1,1,45));
    private ToDoItem compareMonth2 = quickItem(new Date(2012,2,1,1,45));
    private ToDoItem compareMonth3 = quickItem(new Date(2012,3,1,1,45));

    private ToDoItem compareYear1 = quickItem(new Date(2010,1,1,1,45));
    private ToDoItem compareYear2 = quickItem(new Date(2011,1,1,1,45));
    private ToDoItem compareYear3 = quickItem(new Date(2012,1,1,1,45));

    /**
     * checks to make sure the date is filtered by the minute properly
     */
    @Test
    public void testDateFilterbyMin() {
        ArrayList<ToDoItem> items = new ArrayList<ToDoItem>();

        items.add(compareMins1);
        items.add(compareMins2);
        items.add(compareMins3);
        
		Date date = compareMins2.getDueDate();
        new FilterDate(date).filter(items);

        for (ToDoItem item : items) {
            junit.framework.Assert.assertFalse(compareMins3.equals(item));
        }
        
        junit.framework.Assert.assertTrue("personal1 is not in the list",items.contains(compareMins1));
        junit.framework.Assert.assertTrue("personal2 is not in the list",items.contains(compareMins2));
  
    }
    
    /**
     * checks to make sure the date is filtered by the hour properly
     */
    @Test
    public void testDateFilterbyHour() {
        ArrayList<ToDoItem> items = new ArrayList<ToDoItem>();

        items.add(compareHours1);
        items.add(compareHours2);
        items.add(compareHours3);
        
		Date date = compareHours2.getDueDate();
 
        new FilterDate(date).filter(items);
        for (ToDoItem item : items) {
            junit.framework.Assert.assertFalse("item 3 is in the list", compareHours3.equals(item));
        }
        
        junit.framework.Assert.assertTrue("item 1 is not in the list",items.contains(compareHours1));
        junit.framework.Assert.assertTrue("item 2 is not in the list",items.contains(compareHours2));
  
    }    
    
    /**
     * checks to make sure the date is filtered by the day properly
     */
    @Test
    public void testDateFilterbyDay() {
        ArrayList<ToDoItem> items = new ArrayList<ToDoItem>();

        items.add(compareDay1);
        items.add(compareDay2);
        items.add(compareDay3);
        
		Date date = compareDay2.getDueDate();
 
        new FilterDate(date).filter(items);
        for (ToDoItem item : items) {
            junit.framework.Assert.assertFalse("item 3 is in the list", compareDay3.equals(item));
        }
        
        junit.framework.Assert.assertTrue("item 1 is not in the list",items.contains(compareDay1));
        junit.framework.Assert.assertTrue("item 2 is not in the list",items.contains(compareDay2));
  
    }    
    
    /**
     * checks to make sure the date is filtered by the month properly
     */
    @Test
    public void testDateFilterbyMonth() {
        ArrayList<ToDoItem> items = new ArrayList<ToDoItem>();

        items.add(compareMonth1);
        items.add(compareMonth2);
        items.add(compareMonth3);
        
		Date date = compareMonth2.getDueDate();
 
        new FilterDate(date).filter(items);
        for (ToDoItem item : items) {
            junit.framework.Assert.assertFalse("item 3 is in the list", compareMonth3.equals(item));
        }
        
        junit.framework.Assert.assertTrue("item 1 is not in the list",items.contains(compareMonth1));
        junit.framework.Assert.assertTrue("item 2 is not in the list",items.contains(compareMonth2));
  
    }    
    
    /**
     * checks to make sure the date is filtered by the year properly
     */
    @Test
    public void testDateFilterbyYear() {
        ArrayList<ToDoItem> items = new ArrayList<ToDoItem>();

        items.add(compareYear1);
        items.add(compareYear2);
        items.add(compareYear3);
        
		Date date = compareYear2.getDueDate();
        new FilterDate(date).filter(items);
        for (ToDoItem item : items) {
            junit.framework.Assert.assertFalse("item 3 is in the list", compareYear3.equals(item));
        }
        
        junit.framework.Assert.assertTrue("item 1 is not in the list",items.contains(compareYear1));
        junit.framework.Assert.assertTrue("item 2 is not in the list",items.contains(compareYear2));
  
    }    
    
    /**
     * creates a todoitem with the inputted date
     * @param date date to create the todoitem with
     * @return the item with the inputted date
     */
    public ToDoItem quickItem(Date date) {
        return (new ToDoItem(0, "Title", null , null, date, null, null));
    }

}


